import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:zenge_web_flutter/custom/appBar_widget.dart';
import 'package:zenge_web_flutter/custom/custom_products_view.dart';
import 'package:zenge_web_flutter/custom/custom_widget.dart';
import 'package:zenge_web_flutter/date_base/ecology_date.dart';
import 'package:zenge_web_flutter/view/keep_alive.dart';

import 'state.dart';

Widget buildView(
    EcologyState state, Dispatch dispatch, ViewService viewService) {
  TextStyle style4 =
      TextStyle(fontSize: 14, color: Color.fromRGBO(126, 146, 177, 1));
  TextStyle style2 = TextStyle(
    fontSize: 14,
    color: Colors.grey,
  );
  double screenWidth = 1920;
  double screenHeight = (650 / 1920) * 1920;
  return Scaffold(
    body: Container(
      color: Colors.white,
      width: MediaQuery.of(viewService.context).size.width,
      alignment: Alignment.center,
      child: Container(
        width: screenWidth,
        alignment: Alignment.center,
        child: ListView(
          shrinkWrap: true,
          controller: state.scrollController,
          children: [
            Stack(
              children: [
                Positioned(
                  top: 65,
                  child: Container(
                    width: screenWidth,
                    height: 380/1920*screenWidth,
                    child: new Image.network(
                      'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2226943.jpg',
                      fit: BoxFit.fill,
                    ),
                  ),
                ),
                AppBarWidget(boxHeight: 380,),
              ],
            ),
            ImageWidget(
              width: screenWidth,
              height: 800 / 1920 * screenWidth,
              imageUrl:
                  'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2178966.jpg',
            ),
            ImageWidget(
              width: screenWidth,
              height: 800 / 1920 * screenWidth,
              imageUrl:
                  'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2176887.jpg',
            ),
            ImageWidget(
              width: screenWidth,
              height: 800 / 1920 * screenWidth,
              imageUrl:
                  'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2177392.jpg',
            ),
            ImageWidget(
              width: screenWidth,
              height: 800 / 1920 * screenWidth,
              imageUrl:
                  'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2178900.jpg',
            ),
            ImageWidget(
              width: screenWidth,
              height: 800 / 1920 * screenWidth,
              imageUrl:
                  'http://nwzimg.wezhan.hk/contents/sitefiles3603/18018508/images/2179058.jpg',
            ),
            Container(
              width: screenWidth,
              height: 70,
              color: Colors.white,
              child: Stack(
                children: [
                  Positioned(
                      top: 20,
                      left: (screenWidth - 200) / 2,
                      child: Container(
                          width: 200,
                          child: Text(
                            '使用场景',
                            style: TextStyle(fontSize: 35, color: Colors.black),
                          ))),
                ],
              ),
            ),
            Container(
              width: screenWidth,
              height: 500,
              child: Stack(
                children: [
                  Positioned(
                    top: 20,
                    left: 0,
                    child: Container(
                      width: screenWidth,
                      padding:
                          EdgeInsets.symmetric(horizontal: screenWidth / 5),
                      child: GridView.builder(
                          shrinkWrap: true,
                          itemCount: scenesUsedList.length,
                          padding: EdgeInsets.all(10),
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 3,
                            crossAxisSpacing: 10,
                            mainAxisSpacing: 10,
                            childAspectRatio: 320 / 190,
                          ),
                          itemBuilder: (BuildContext context, int index) {
                            return EcologyView(
                              image01: scenesUsedList[index].image1,
                              image02: scenesUsedList[index].image2,
                            );
                          }),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 30,),
            Container(
              width: screenWidth,
              color: Colors.white,
              height: 70,
              child: Stack(
                children: [
                  Positioned(
                      top: 20,
                      left: (screenWidth - 200) / 2,
                      child: Container(
                          width: 200,
                          child: Text(
                            '合作伙伴',
                            style: TextStyle(fontSize: 35, color: Colors.black),
                          ))),
                ],
              ),
            ),
            SizedBox(height: 30,),
            Container(
              height: 130,
              child: ListView.builder(
                scrollDirection: Axis.horizontal,
                  itemCount: imageList.length,
                  controller: state.controller,
                  itemBuilder: (BuildContext conetxt,int index){
                return Container(
                    width: 300,
                    height: 130,
                    color: Colors.white,
                    alignment: Alignment.center,
                    child: Image.network(imageList[index],fit: BoxFit.fill,));
              }),
            ),
            SizedBox(height: 70,),
            KeepAliveWidget(viewService.buildComponent("bottom_info")),
          ],
        ),
      ),
    ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Colors.white,
        onPressed: () {
          // scrollController 通过 animateTo 方法滚动到某个具体高度
          // duration 表示动画的时长，curve 表示动画的运行方式，flutter 在 Curves 提供了许多方式
          state.scrollController.animateTo(0.0,
              duration: Duration(milliseconds: 500),
              curve: Curves.decelerate);
        },
        child: Icon(Icons.arrow_upward_sharp,color: Colors.grey,size: 40,),
      )
  );
}
